#pragma once

#include "ChatUtils.h"


class ChatLogicModule : public CDuiObject
{
public Dui_Signals:
	sigslot::Signal<SessionId> newSession;
	sigslot::Signal<SessionId, ChatMsgId> recvChatMsg;
	sigslot::Signal<> recvFriendList;

public:
	ChatLogicModule();
	~ChatLogicModule();

	void Run();

	void SendChatMessage(SessionId sessionId, const std::TString& msg);
	void SendLoginMessage();
	void SendSettingMessage(int settingType, const std::TString& val);

	std::TString GetMyAccount();

	const FriendMap& GetFriends();
	const ChatSession* GetChatSession(SessionId sessionId);
	const ChatMsg* GetChatMessage(SessionId sessionId, ChatMsgId msgId);

	std::TString GetSessionName(SessionId sessionId);
	std::TString GetSessionAccount(SessionId sessionId);

	std::TString GetIconFromAccount(const std::TString& account);
	std::TString GetNameFromAccount(const std::TString& account);
	std::TString GetAccountFromName(const std::TString& name);

	void CreateSession(const std::TString& account);
	void ChangeFriendSetting(const std::TString& account, int settingType, const CVar& val);

private:
	void Init();

	void OnRecvMessage(int msgId, const StringList& msg);
	void OnRecvChatMessage(const StringList& msg);
	void OnRecvFriendListMessage(const StringList& msg);

	std::TString GetRecverAccount(SessionId id);

private:
	ChatSessionMap m_ChatSessions;

	FriendMap m_Friends;

	AccountInfo m_MyInfo;
};
